/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
private:
    vector<int> res;
public:
    void Visit(TreeNode* root)
    {
        if(root==nullptr)  return;
        stack<TreeNode*> st;
        while(!st.empty()||root!=nullptr){
            if(root!=nullptr){
                st.push(root);
                root=root->left;
            }else{
                TreeNode* node=st.top();
                st.pop();
                res.emplace_back(node->val);
                root=node->right;
            }
        }
    }
    bool isValidBST(TreeNode* root) {
        bool flag=true;
        Visit(root);
        int size=res.size();
        for(int i=1;i<size;i++){
            if(res[i-1]>=res[i]) flag=false;
        }
        return flag;
    }
};